﻿// HSS.Data.DataParameter.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       DataParameter.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   02/23/2011
// ----------------------------------------------------------------------------
namespace HSS.Data
{
	#region DataParameter
	/// <summary>
	/// DataParameter is a simple class used to fill a SqlParameter for use with the <see cref="DataAccessService{T}"/>.
	/// </summary>
	public class DataParameter
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name">The parameter Name.</param>
		/// <param name="value">The parameter Value.</param>
		/// <param name="direction">Specifies the type of the parameter within a query. Default: Input</param>
		/// <exception cref="System.NotSupportedException">The <see cref="System.Data.ParameterDirection.ReturnValue"/> is not a supported <see cref="System.Data.ParameterDirection"/>.</exception>
		/// <remarks>
		/// <para>
		/// <b>Note:</b> The <see cref="System.Data.ParameterDirection.ReturnValue"/> is not a supported <see cref="System.Data.ParameterDirection"/>.
		/// </para>
		/// </remarks>
		public DataParameter(string name, object value, System.Data.ParameterDirection direction = System.Data.ParameterDirection.Input)
		{
			if (direction == System.Data.ParameterDirection.ReturnValue)
				throw new System.NotSupportedException("The ReturnValue is not a supported System.Data.ParameterDirection.");
			Guard.ArgumentNotNullOrEmpty(name, "name");
			this.Name = name;
			this.Value = value;
			this._direction = direction;
		}
		/// <summary>
		/// Gets or sets the parameter Name
		/// </summary>
		public string Name { get; set; }
		/// <summary>
		/// Gets or sets the parameter Value
		/// </summary>
		public object Value { get; set; }
		/// <summary>
		/// Gets or sets the parameter direction.
		/// </summary>
		/// <exception cref="System.NotSupportedException">The <see cref="System.Data.ParameterDirection.ReturnValue"/> is not a supported <see cref="System.Data.ParameterDirection"/>.</exception>
		/// <remarks>
		/// <para>
		/// <b>Note:</b> The <see cref="System.Data.ParameterDirection.ReturnValue"/> is not a supported <see cref="System.Data.ParameterDirection"/>.
		/// </para>
		/// </remarks>
		public System.Data.ParameterDirection Direction
		{
			get { return _direction; }
			set
			{
				if (value == System.Data.ParameterDirection.ReturnValue)
					throw new System.NotSupportedException("The ReturnValue is not a supported System.Data.ParameterDirection.");
				_direction = value;
			}
		} System.Data.ParameterDirection _direction = System.Data.ParameterDirection.Input;
	}
	#endregion

	#region DataParameter<T>
	/// <summary>
	/// DataParameter&lt;T&gt; is a generic class used to fill a SqlParameter for use with the <see cref="DataAccessService{T}"/>.
	/// </summary>
	/// <typeparam name="T">The Type of the DataParameter <see cref="Value"/> property.</typeparam>
	public sealed class DataParameter<T> : DataParameter
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name">The parameter Name.</param>
		/// <param name="value">The parameter Value.</param>
		/// <param name="direction">Specifies the type of the parameter within a query. Default: Input</param>
		/// <exception cref="System.NotSupportedException">The <see cref="System.Data.ParameterDirection.ReturnValue"/> is not a supported <see cref="System.Data.ParameterDirection"/>.</exception>
		/// <remarks>
		/// <para>
		/// <b>Note:</b> The <see cref="System.Data.ParameterDirection.ReturnValue"/> is not a supported <see cref="System.Data.ParameterDirection"/>.
		/// </para>
		/// </remarks>
		public DataParameter(string name, T value, System.Data.ParameterDirection direction = System.Data.ParameterDirection.Input)
			: base(name, value, direction)
		{
		}
		/// <summary>
		/// Gets or sets the parameter Value.
		/// </summary>
		/// <remarks>
		/// <b>NOTE:</b> The value is cast to Type T without validation.
		/// </remarks>
		public new T Value
		{
			get { return (T)base.Value; }
			set { base.Value = value; }
		}
	}
	#endregion
}